<template>
    <section>
        <!--工具条-->
        <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
            <el-form :inline="true" :model="filters">
                <el-form-item>
                    <el-input v-model="filters.name" placeholder="关键字"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" v-on:click="getLogs">查询</el-button>
                </el-form-item>
            </el-form>
        </el-col>

        <!--列表-->
        <el-table :data="logs" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
            <el-table-column type="selection" width="55">
            </el-table-column>
            <el-table-column type="index" label="排序" width="60" >
            </el-table-column>
            <el-table-column prop="id" label="操作顺序" width="100" sortable>
            </el-table-column>
            <el-table-column prop="ip" label="Ip地址" width="150" >
            </el-table-column>
            <el-table-column prop="module" label="模块" width="120" sortable>
            </el-table-column>
            <el-table-column prop="operation" label="操作类型" width="120" sortable>
            </el-table-column>
            <el-table-column prop="res_method" label="操作方法" width="250"  sortable>
            </el-table-column>
            <el-table-column prop="params" label="参数" width="300"   sortable>
            </el-table-column>
            <el-table-column prop="excute_time" label="操作时间" min-width="100"   sortable>
            </el-table-column>
        </el-table>

        <!--工具条-->
        <el-col :span="24" class="toolbar">
            <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>
            <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="pageSize" :current-page.sync="currentPage" :total="total" style="float:right;">
            </el-pagination>
        </el-col>

    </section>
</template>

<script>
    import util from '../../common/js/util'
    //import NProgress from 'nprogress'
    import { getDepartmentListPage, removeDepartment, batchRemoveDepartment, editDepartment, addDepartment } from '../../api/api';

    export default {
        data() {
            return {
                filters: {
                    name: ''
                },
                logs: [],
                total: 0,
                currentPage: 1,
                pageSize:5,
                listLoading:false,
                sels: [],//列表选中列
                //编辑界面数据
            }
        },
        methods: {

            handleCurrentChange(val) {
                this.currentPage = val;
                this.getLogs();
                this.$http.delete
            },
            //获取用户列表
            getLogs(){
                let query = {
                    currentPage: this.currentPage,
                    pageSize: this.pageSize,
                    keyword: this.filters.name
                };
                this.listLoading = true;
                //NProgress.start();
                this.$http.post("/logs/list",query)
                    .then(result=>{
                        this.listLoading=false;
                        result=result.data;
                        this.logs=result.rows;
                        this.total=result.total;

                        this.$message({
                            message:"加载成功",
                            type:"success"
                        })
                    })
                    .catch(result=>{
                        this.$message({
                            message:"加载失败",
                            type:"error"
                        })

                    })

            },
            selsChange: function (sels) {
                this.sels = sels;
            },
            //批量删除
            batchRemove: function () {
                var ids = this.sels.map(item => item.id);
                this.$confirm('确认删除选中记录吗？', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    //NProgress.start();
                    let para = { ids: ids };
                    //发请求
                    this.$http.patch("/logs",ids)
                        .then(result=>{
                            //接收一波参数再说
                            result=result.data
                            if(result.success){
                                //删除成功定位到第一页
                                this.currentPage=1;
                                //刷新列表
                                this.getLogs();
                                //关闭忙等框
                                this.listLoading = false;
                            }else {
                                //后端删除失败就不做任何操作,关闭忙等框
                                this.listLoading = false;
                            }

                            //提示后端返回信息
                            this.$message({
                                message: result.message,
                                type: 'success'
                            });
                        }).catch(() => {
                        this.$message({
                            message: '殴打程序员',
                            type: "error"
                        });
                    });

                })
            }
        },
        mounted() {
            this.getLogs();

        }
    }

</script>

<style scoped>

</style>